package com.neusoft.courseSelect.service.impl;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.neusoft.courseSelect.domain.RespForecast;
import com.neusoft.courseSelect.service.IForcast;
import com.neusoft.data.domain.SerForecast;
import com.neusoft.wenXinYiYan.util.HttpClientUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class Forcast implements IForcast {

    @Value("${forecast.url}")
    String url;

    @Override
    public List<RespForecast> Forcast(String stuNum) {

        Map<String, String> requestData = new HashMap<>();
        requestData.put("stuNum", stuNum);

        Gson gson = new Gson();
        String ques = gson.toJson(requestData);
        System.out.println(ques);

        TypeToken<List<RespForecast>> typeToken = new TypeToken<List<RespForecast>>() {};

        try {
            String result = HttpClientUtils.post(url, ques);
            return new Gson().fromJson(result, typeToken.getType());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
